package com.ysw.springbootproject.service.impl;

import com.ysw.springbootproject.dao.PictureDao;
import com.ysw.springbootproject.entity.Picture;
import com.ysw.springbootproject.service.PictureService;
import com.ysw.springbootproject.utils.PageResult;
import com.ysw.springbootproject.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 月上微
 * @date 2025/1/10
 * @since 15:30
 */
@Service("pictureService")
public class PictureServiceImpl implements PictureService {

    @Autowired
    private PictureDao pictureDao;

    /**
     * 获取图片列表
     *
     * @param pageUtil 分页参数
     * @return PageResult
     */
    @Override
    public PageResult getPicturePage(PageUtil pageUtil) {
        List<Picture> pictures = pictureDao.findPictures(pageUtil);
        int total = pictureDao.getTotalPictures(pageUtil);
        PageResult pageResult = new PageResult(pictures, total, pageUtil.getLimit(), pageUtil.getPage());
        return pageResult;
    }

    /**
     * 获取图片列表
     *
     * @param id 查询参数
     * @return Picture
     */
    @Override
    public Picture queryObject(Integer id) {
        return pictureDao.findPictureById(id);
    }

    /**
     * 新增图片对象
     *
     * @param picture 图片对象
     * @return int
     */
    @Override
    public int save(Picture picture) {
        return pictureDao.insertPicture(picture);
    }

    /**
     * 更新图片对象
     *
     * @param picture 图片对象
     * @return int
     */
    @Override
    public int update(Picture picture) {
        return pictureDao.updatePicture(picture);
    }

    /**
     * 删除图片对象
     *
     * @param id 图片对象
     * @return int
     */
    @Override
    public int delete(Integer id) {
        return pictureDao.deletePicture(id);
    }

    /**
     * 批量删除图片对象
     *
     * @param ids 图片对象
     * @return int
     */
    @Override
    public int deleteBatch(Integer[] ids) {
        return pictureDao.deleteBatch(ids);
    }
}
